angular.module('charitySociety.controller', []).controller('charitySocietyController', ['$scope', '$charitySocietyService', '$sce', '$stateParams',
    function ($scope, $charitySocietyService, $sce, $stateParams) {
        
        $scope.items = [{
                name:'简介',
                url:'introduce',
                showChildren:false,
            },{
                name:'章程',
                url:'rule',
                showChildren:false
            },{
                name:'财务',
                url:'finance',
                showChildren:false
            },{
                name:'项目',
                url:'project',
                showChildren:false
            },{
                name:'其他',
                url:'other',
                showChildren:false
            }];

        $scope.contentHtml = '', $scope.currentItem = $stateParams.articleType ? $stateParams.articleType : 'introduce';

        var articleTypes = {
            'introduce': {index:1,text:"简介"},
            'rule': {index:2,text:"章程"},
            'finance': {index:3,text:"财务"},
            'project': {index:4,text:"项目"},
            'other': {index:5,text:"其他"}
        };
        
        $scope.navClicked = function (articleType) {
            $scope.currentItem = articleType;
            $charitySocietyService.getArticleDetail({articleType: articleTypes[articleType].index}, function (data) {
                $scope.contentHtml = $sce.trustAsHtml(data.data[0] ? data.data[0].content : '');

            }, function (err) {
                console.error(err);
            });
        };
        $scope.navClicked($scope.currentItem);

    }]);